<?php


namespace Module\Work\Admin\Controller;


use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;
use ModStart\Grid\GridFilter;
use ModStart\Support\Concern\HasFields;
use Module\Work\Model\Work;
use Module\Work\Model\WorkCategory;
use Module\Work\Type\WorkStatus;

class WorkController extends Controller
{
    use HasAdminQuickCRUD;

    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder
            ->init(Work::class)
            ->field(function ($builder) {
                /** @var HasFields $builder */
                $builder->id('id', 'ID');
                $builder->select('categoryId', '分类')->optionModelTree(WorkCategory::class);
                $builder->text('name', '任务名称');
                $builder->richHtml('content', '内容')->listable(false);
                $builder->type('status', '状态')->type(WorkStatus::class, [
                    WorkStatus::NOSTART => 'danger',
                    WorkStatus::DOING => 'danger',
                    WorkStatus::FINISH => 'success'
                ])->required();
                $builder->text('leaderId','发布人姓名');
                $builder->text('operateId','负责人姓名');
                $builder->display('created_at', L('Created At'))->listable(false);
                $builder->display('updated_at', L('Updated At'))->listable(false);
            })
            ->gridFilter(function (GridFilter $filter) {
                $filter->eq('id', L('ID'));
                $filter->like('title', L('Title'));
            })
            ->title('任务管理列表')
            ->defaultOrder(['id', 'asc'])
            ->canSort(true);
    }
}
